package com.web.shop.service.impl;


import com.web.shop.mapper.TbBrandMapper;
import com.web.shop.pojo.TbBrand;
import com.web.shop.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;


@Service
public class BrandServiceImpl implements BrandService {
	
	@Autowired
	private TbBrandMapper brandMapper;
	
	@Override
	public List<TbBrand> findAll() {
		return brandMapper.selectByExample(null);
	}

	@Override
	public TbBrand findOne(Long id) {
		return brandMapper.selectByPrimaryKey(id);
	}

	@Override
	public void update(TbBrand brand) {
		//判断 news是否有id
		if (ObjectUtils.isEmpty(brand.getId())) {
			brandMapper.insert(brand);
		} else {
			brandMapper.updateByPrimaryKey(brand);
		}
	}
	@Override
	public void delete(Long id) {
			brandMapper.deleteByPrimaryKey(id);
	}
}
